package com.ai.entity.made.page;

import cn.hutool.core.util.StrUtil;
import com.ai.entity.BasePage;
import com.ai.entity.made.ModbusNodeInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import static com.ai.common.constant.ModbusConstants.MODBUS_REGISTER_DEFAULT_ADDRESS;

/**
 * @Author jiaok
 * @Date 2024-11-27 10:13
 */
@Data
public class ModbusNodeInfoPage   extends BasePage<ModbusNodeInfo> {

    @ApiModelProperty(value = "modbus服务id")
    private String modbusServerId;

    @ApiModelProperty(value = "节点名称")
    private String nodeName;

    @ApiModelProperty(value = "偏移量，默认从40001开始， （若读取40003，则需设为40003-40001=2）")
    private Integer offset;

    @ApiModelProperty(value = "从机id")
    private Integer slaveId;

    @Override
    public QueryWrapper<ModbusNodeInfo> getQuery(QueryWrapper<ModbusNodeInfo> queryWrapper) {
        return super.getQuery(queryWrapper)
                .eq(StrUtil.isNotBlank(modbusServerId),"modbus_server_id",modbusServerId)
                .like(StrUtil.isNotBlank(nodeName),"node_name",nodeName)
                .eq((null != offset), "slave_id",slaveId);
    }
}
